﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KL.Store.Core.Domain;
using TN.Data;

namespace KL.Store.Data
{
    public class dbAddress
    {
        #region Insert

        public static short Insert(int UserId, string AddressName, string Name, string TaxOffice, string TaxNo, string Address1, string Address2, string County, string PostalCode, short Country, short City, int CreateUser, string Phone, int UserType = 0)
        {
            return (short)SqlHelper.ExecuteScalar(dbParameters.dsnStore, "SPR_ESTORE_Address_Insert", new object[] { UserId, Convert2.ToString(AddressName), Convert2.ToString(Name), Convert2.ToString(TaxOffice), Convert2.ToString(TaxNo), Convert2.ToString(Address1), Convert2.ToString(Address2), Convert2.ToString(County), Convert2.ToString(PostalCode), Country, City, CreateUser, UserType, Convert2.ToString(Phone) });
        }

        #endregion

        #region Update

        public static void Update(int UserId, short AddressId, string AddressName, string Name, string TaxOffice, string TaxNo, string Address1, string Address2, string County, string PostalCode, short Country, short City, int UpdateUser, string Phone)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Address_Update", new object[] { UserId, AddressId, Convert2.ToString(AddressName), Convert2.ToString(Name), Convert2.ToString(TaxOffice), Convert2.ToString(TaxNo), Convert2.ToString(Address1), Convert2.ToString(Address2), Convert2.ToString(County), Convert2.ToString(PostalCode), Country, City, UpdateUser, Convert2.ToString(Phone) });
        }

        #endregion

        #region Delete

        public static void Delete(int UserId, short AddressId)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Address_Delete", new object[] { UserId, AddressId });
        }

        #endregion

        #region Get

        public static Address Get(int UserId, short AddressId)
        {
            IList<Address> objectList = new List<Address>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Address_Get", objectList, new object[] { UserId, AddressId });
            return objectList.FirstOrDefault();
        }

        #endregion

        #region GetList

        public static IList<Address> GetList(int UserId, int UserType = 0)
        {
            IList<Address> objectList = new List<Address>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Address_List", objectList, new object[] { UserId, UserType });

            return objectList;
        }

        #endregion

        #region GetDDL

        public static IList<AddressDDL> GetDDL(int UserId, int UserType = 0)
        {
            IList<AddressDDL> objectList = new List<AddressDDL>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Address_Combo", objectList, new object[] { UserId, UserType });

            return objectList;
        }

        #endregion

        #region VisitorToUser

        public static void VisitorToUser(int VisitorId, int UserId)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Address_VisitorToUser", new object[] { VisitorId, UserId });
        }

        #endregion
    }
}
